package com.lion.seaman.worker.plugin;

import java.util.concurrent.ConcurrentHashMap;

public class PluginCache {
    public static final PluginCache CACHE = new PluginCache();
    ConcurrentHashMap<String, Plugin> data = new ConcurrentHashMap<>();

    public void addPlugin(Plugin plugin) {
        this.data.put(plugin.createPluginId(), plugin);
    }

    public Plugin getPlugin(String pluginId) {
        return this.data.get(pluginId);
    }

    public Plugin getPlugin(Plugin plugin) {
        return this.data.get(plugin.createPluginId());
    }

    public void close() {
        for (Plugin plugin : data.values()) {
            plugin.close();
        }
    }

}
